Crystal Reports Integration

Generate PDF Report

Description
This example demonstrates how to integrate Crystal Reports with an Iron Speed Designer-application.
Variables
Crystal Report File
Select a crystal report file.
Button Control
Select a button
Applies to
P_Button Control class
Code
 
	/// 
	///Override the ${Button Control}_Click and call DisplayReportAsPD() function
	/// 
	public void ${Button Control}_Click(Object sender, EventArgs args)
	{
	    CrystalDecisions.CrystalReports.Engine.ReportDocument crReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
	    crReportDocument.Load(@"${Crystal Report File}");
	    DisplayReportAsPDF(crReportDocument);
	}
 
Applies to
P_Button Control class
Code
 
	/// 
	/// This function creates an instance of the Crystal Report in PDF format and displays it
	/// 
	private void DisplayReportAsPDF(CrystalDecisions.CrystalReports.Engine.ReportDocument reportObject) 
	{ 

	    // Declare the necessary Crystal Reports objects.
	    CrystalDecisions.CrystalReports.Engine.Table dbTable;
	    CrystalDecisions.Shared.TableLogOnInfo dbLogin;
	    ExportOptions crExportOptions;
	    DiskFileDestinationOptions crDiskFileDestinationOptions;

        // Add login information if needed.
        //reportObject.SetDatabaseLogon("UserID", "password")

	    // Create a temporary file to hold the report
	    // use the session ID in the filename to  avoid process conflicts
	    // use a built-in Iron Speed utility function (and the "MapPath" method) to get the current 
	    // application's root path  
	    string fileName;
	    fileName = this.Page.Server.MapPath(BaseClasses.Configuration.ApplicationSettings.Current.AppRootPath) + "\\" 
	    + this.Page.Session.SessionID.ToString() + ".pdf";

	    // Define the Crystal Report output options.
	    crDiskFileDestinationOptions = new DiskFileDestinationOptions();
	    crDiskFileDestinationOptions.DiskFileName = fileName;
	    crExportOptions = reportObject.ExportOptions;
	    crExportOptions.DestinationOptions = crDiskFileDestinationOptions; 
	    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; 
	    crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

	    // Export the document to the temporary file.
	    reportObject.Export();

	    // Create the HTTP Response as PDF and output the file.
	    this.Page.Response.ClearContent();
	    this.Page.Response.ClearHeaders();
	    this.Page.Response.ContentType = "application/pdf";
	    this.Page.Response.WriteFile(fileName);
	    this.Page.Response.Flush();

	    //  Clean up the Response object and delete the temporary file.
	    this.Page.Response.Close();
	    System.IO.File.Delete(fileName);
	}

     

Terms of Service Privacy Statement